package com.delivery.deliverysystem.controller;

import com.delivery.deliverysystem.common.ServerResponse;
import com.delivery.deliverysystem.exception.RException;
import com.delivery.deliverysystem.service.DefaultNameService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/defaultName")
@Api(tags = "默认字段接口")
public class DefaultNameController {

    @Autowired
    private DefaultNameService defaultNameService;

    @PostMapping("/updateDefaultName")
    @ApiOperation(value = "更新默认字段",response = ServerResponse.class,httpMethod = "POST")
    public ServerResponse updateDefaultName(@RequestBody Map<String,Object> defaultName){
        try {
            boolean b = defaultNameService.updateDefaultName(defaultName);
            return b?ServerResponse.createBySuccess("更新成功"):ServerResponse.createByError("更新失败");
        }catch (RException re){
            return ServerResponse.createByError(re.getMsg());
        }catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByError("更新失败");
        }
    }

}
